<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9_收集表单数据</title>
</head>

<body>
    <div id="main"></div>

    <!-- 引入react核心库，引入对象：React -->
    <script src="./js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM，引入对象：ReactDOM -->
    <script src="./js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script src="./js/babel.min.js"></script>
    <!-- 引入对组件属性约束，引入对象：PropTypes -->
    <script src="./js/prop-types.js"></script>

    <script type="text/babel">

        /* 
            非受控组件：
            受控组件：
        */

        class Box extends React.Component {

            // 初始化状态
            state = {
                username: '',
                password: ''
            }

            saveUsername = (event) => {
                this.setState({
                    username: event.target.value
                })
            }

            savePassword = (event) => {
                this.setState({
                    password: event.target.value
                })
            }

            handlerSubmit = (event) => {
                event.preventDefault()
                const { username, password } = this.state
            }

            render() {
                return (
                    <form action="http://127.0.0.1:5500" onSubmit={this.handlerSubmit}>
                        {/*
                            form 不指定请求方式，默认是 get 请求
                            参数以 query 形式传参
                        */}
                        <label>用户：</label>
                        <input onChange={this.saveUsername} type="text" name="username" /><br />
                        <label>密码：</label>
                        <input onChange={this.savePassword} type="text" name="password" /><br />
                        <button>login</button>
                    </form>
                )
            }
        }

        ReactDOM.render(<Box />, document.getElementById('main'))
    </script>
</body>

</html>